<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
  <script type="text/javascript">
      var actRuTaskTable;
  </script>
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <!-- 当前位置 begin -->
        <div class="row h-home-path">
          <div class="col-md-12">
            <ol class="breadcrumb">
              <li><i class="fa fa-home"></i>&nbsp;&nbsp;所在位置</li>
              <li>首页</li>
              <li class="active">待办任务</li>
            </ol>
          </div>
        </div>
        <!-- 当前位置 end -->

        <!-- 查询筛选内容 bagin -->
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="col-md-1 col-sm-1 col-xs-1 text-right">
              <label class="control-labe h-form-label" for="procDefname">流程名称：</label>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-2">
              <input class="form-control" id="procDefname" name="procDefname" type="text" value="">
            </div>
            <div class="col-md-1 col-sm-1 col-xs-1 text-right">
              <label class="control-labe h-form-label" for="taskName">环节名称：</label>
            </div>
            <div class="col-md-2 col-sm-2 col-xs-2">
              <input class="form-control" id="taskName" name="taskName" type="text" value="">
            </div>
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" onclick="ActRuTaskManager.search()" type="button"><i class="fa fa-search">&nbsp;&nbsp;</i>查询
              </button>
              <div id="btnPermission" style="display:none">
                <div class="h-btn-group">
                  <@permission btnType="edit" btnLink="true" btnValue="签收任务" btnClass="btn btn-info" btnId="editBtn"
                  op="act:rutask:claim"/>
                  <@permission btnType="deal" btnLink="true" btnValue="任务办理" btnClass="btn btn-info" btnId="dealBtn"
                  op="act:rutask:deal"/>
                  <@permission btnType="delete" btnLink="true" btnValue="删除" btnId="deleteBtn" btnClass="btn
                  btn-danger" op="act:rutask:del"/>
                  <@permission btnType="view" btnLink="true" btnValue="跟踪" btnId="viewBtn" btnClass="btn btn-warning"
                  op="act:rutask:view"/>
                </div>
              </div>
              <button class="btn btn-default" type="reset"><i class="fa fa-mail-reply">&nbsp;&nbsp;</i>重置</button>
            </div>
          </form>
        </div>

        <!-- 表格 begin -->
        <div class="panel panel-white h-panel">
          <div class="panel-body">
            <table class="table table-striped table-bordered table-hover text-center" id="actRuTask_table"
                   style='width:100%'></table>
          </div>
        </div>
        <!-- 表格 end -->
      </div>
    </div>
    <!-- end: PAGE -->
  </div>
  <!-- end: MAIN CONTAINER -->
  <!-- 新增 end -->
  <!-- end: SUBVIEW SAMPLE CONTENTS -->
</div>
<#include "/common/jslib.html">

<script type="text/javascript">
    $(function () {
        ActRuTaskManager = {
            init: function () {

            },
            search: function () {
                var queryCond = {
                    procDefname: $("#procDefname").val()
                    , taskName: $("#taskName").val()
                };
                actRuTaskTable.options.queryCond = queryCond;
                var tableId = actRuTaskTable.options.tableId;
                $(tableId).DataTable().draw();
            },
            handleOperate: function (operate, url) {
                if (operate == "delete") {
                    ActRuTaskManager.deleteActRuTask(url);
                } else if (operate == "edit") {
                    ActRuTaskManager.claim(url);
                } else if (operate == "view" || operate == "deal") {
                    Jmts.openDialog("dealProcess", url, "流程处理", 550, 1200, 32);
                }
            },
            deleteActRuTask: function (url) {
                var data = {};
                Jmts.deleteItem("确认要删除吗？", url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips("删除成功");
                      ActRuTaskManager.search();
                    } else {
                        Jmts.errorTips(result.msg)
                    }
                });
            },
            claim: function (url) {
                var data = {};
                Jmts.deleteItem("确认要认领吗？", url, data, function (result) {
                    if (result.success) {
                        Jmts.succTips("认领成功");
                      ActRuTaskManager.search();
                    } else {
                        Jmts.errorTips(result.msg)
                    }
                });
            }
        }
        ActRuTaskManager.init();
    });
</script>
<!-- 弹窗下拉 -->
<script type="text/javascript">
    (function () {
        // datatable插件
        actRuTaskTable = new mi.datatable({
            tableId: '#actRuTask_table',
            headerList: [
                '流程名称',
                '当前环节',
                '流程版本',
                '创建时间',
                '操作'
            ],
            headerName: [
                'procDefname',
                'taskName',
                'procDefversion',
                'createTime',
                'operate'
            ],
            ajaxUrl: '/act/task/todoData',
            queryCond: function () {

            },
            columnDefs: [],
            paging: true,
            dataSrc: function (data) {
                for (var i in data) {
                    var taskId = data[i]['taskId'];
                    var taskName = data[i]['taskName'];
                    var taskDefKey = data[i]['taskDefKey'];
                    var procInsId = data[i]['procInsId'];
                    var procDefId = data[i]['procDefId'];
                    var status = data[i]['status'];
                    var executionId = data[i]['executionId'];
                    var assignee = data[i]['assignee'];
                    if (assignee == null || assignee == "") {//认领
                        if ($("#editBtn") != null && $("#editBtn") != undefined) {
                            var url = "/act/task/claim?taskId=" + taskId;
                            $("#editBtn").attr("href", "javascript:ActRuTaskManager.handleOperate('edit', '" + url + "')");
                        }
                        $("#dealBtn").hide();
                    } else {//任务办理
                        var url = "/act/task/form?taskId=" + taskId +
                            "&taskName=" + taskName + "&taskDefKey=" + taskDefKey +
                            "&procInsId=" + procInsId +
                            "&procDefId=" + procDefId + "&status=" + status;
                        if ($("#dealBtn") != null && $("#dealBtn") != undefined) {
                            $("#dealBtn").attr("href", "javascript:ActRuTaskManager.handleOperate('deal', '" + url + "')");
                        }
                        $("#editBtn").hide();
                    }
                    //删除
                    if (executionId == "") {
                        if ($("#deleteBtn") != null && $("#deleteBtn") != undefined) {
                            var url = "/act/task/deleteTask?taskId=" + taskId;
                            $("#deleteBtn").attr("href", "javascript:ActRuTaskManager.handleOperate('delete','" + url + "')");
                        }
                    } else {
                        $("#deleteBtn").hide();
                    }
                    //流程跟踪
                    if ($("#viewBtn") != null && $("#viewBtn") != undefined) {
                        var url = "/act/task/diagramViewer?definitionId=" + procDefId + "&instanceId=" +
                            procInsId;
                        $("#viewBtn").attr("href", "javascript:ActRuTaskManager.handleOperate('view','" + url + "')");
                    }
                    data[i]['procDefversion'] = "V:" + data[i]['procDefversion'];
                    data[i]['operate'] = $("#btnPermission").html();
                }
                return data;
            }
        });
    })();
</script>
</body>
</html>
